/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Jov
 */
@Entity
@Table(name = "calendars")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Calendars.findAll", query = "SELECT c FROM Calendars c"),
    @NamedQuery(name = "Calendars.findByCalendarId", query = "SELECT c FROM Calendars c WHERE c.calendarsPK.calendarId = :calendarId"),
    @NamedQuery(name = "Calendars.findByUserId", query = "SELECT c FROM Calendars c WHERE c.calendarsPK.userId = :userId"),
    @NamedQuery(name = "Calendars.findByNumEvents", query = "SELECT c FROM Calendars c WHERE c.numEvents = :numEvents")})
public class Calendars implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CalendarsPK calendarsPK;
    @Column(name = "num_events")
    private Integer numEvents;
    @JoinColumn(name = "user_id", referencedColumnName = "user_id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Users users;

    public Calendars() {
    }

    public Calendars(CalendarsPK calendarsPK) {
        this.calendarsPK = calendarsPK;
    }

    public Calendars(int calendarId, int userId) {
        this.calendarsPK = new CalendarsPK(calendarId, userId);
    }

    public CalendarsPK getCalendarsPK() {
        return calendarsPK;
    }

    public void setCalendarsPK(CalendarsPK calendarsPK) {
        this.calendarsPK = calendarsPK;
    }

    public Integer getNumEvents() {
        return numEvents;
    }

    public void setNumEvents(Integer numEvents) {
        this.numEvents = numEvents;
    }

    public Users getUsers() {
        return users;
    }

    public void setUsers(Users users) {
        this.users = users;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (calendarsPK != null ? calendarsPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Calendars)) {
            return false;
        }
        Calendars other = (Calendars) object;
        if ((this.calendarsPK == null && other.calendarsPK != null) || (this.calendarsPK != null && !this.calendarsPK.equals(other.calendarsPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.meteocal.entities.Calendars[ calendarsPK=" + calendarsPK + " ]";
    }
    
}
